<?php

include dirname(dirname(__FILE__)) . '/include/common.php';

class webServiceResendConfirm extends core {
    public function process() {
        $data = array();
        $email = $this->_cleanEmail($_POST['userEmail']);
        
        //CHeck validate
        $email = $this->db->escape($email);
        $user = $this->db->get_row("select * from users where email='" . $email . "'");
        
        if ($user) {
            if ($user->active == 0) {
                /* If userEmail is found in the database and account hasn't been activated: => error code 2 */
                $result= $this->_sendMail($email, $user->confirmation_code);
                $this->_JSONResponse(array('error' => 0,'result'=>$result));
            }
        } else{
             $this->_JSONResponse(array('error' => 1));
        }
    }
    
    protected function _sendMail($email, $confirmation_code) {
        $confirmmation_url = $_SERVER['HTTP_HOST'] . '/confirm.php?code=' . $confirmation_code;
        $subject = "Your registration with Wedding Helper";
        $content = "Thank you for submitting your registration information to Wedding Helper! 
                     <br>Please click <a href='" . $confirmmation_url . "'>here</a> to activate your account.
                    <br>The Wedding Helper Team";
        return $this->send_mail($email, $subject, $content);
    }

}

$processor = new webServiceResendConfirm();
$processor->process();
?>